package com.xiaoyu.awakening.ai.index.config;

import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * 系统线程池配置，todo:后续考虑抽到common
 *
 * @author wangxiaoyu
 * @date 2025/6/30 10:02
 * @since v1.0
 */
@Setter
@Getter
@ConfigurationProperties(prefix = "awk.thread.pools")
public class AwkThreadPoolProperties {
    private Map<String, PoolConfigItem> threadPoolConfig = new HashMap<>();

    @Setter
    @Getter
    public static class PoolConfigItem {
        private Integer corePoolSize;
        private Integer maximumPoolSize;
        private Long keepAliveTime;
        private Integer queueCapacity;
        private String threadNamePrefix;
        private Boolean daemon = false;
        private Integer priority = Thread.NORM_PRIORITY;
        private String threadGroupName;

        // 拒绝策略配置，可配置为 ABORT、CALLER_RUNS、DISCARD、DISCARD_OLDEST
        private RejectedPolicy rejectedPolicy = RejectedPolicy.ABORT;

        public enum RejectedPolicy {
            /**
             * 直接抛出 RejectedExecutionException 异常
             */
            ABORT,
            /**
             * 由提交任务的线程来执行该任务
             */
            CALLER_RUNS,
            /**
             * 直接丢弃新提交的任务
             */
            DISCARD,
            /**
             * 丢弃队列中最老的任务，然后尝试提交新任务
             */
            DISCARD_OLDEST,
            /**
             * 用户自定义拒绝策略
             */
            USER_DEFINED;
        }
    }
}